<?php
/**
 * Geneone: Content Management Framework
 * Special Namespace
 *
 * http://geneone.neondragon.net/
 *
 * @package Geneone
 * @author Khlo
 * @version 1.0
 * @copyright 2004-2006 Geneone Development Team
 */
 
class Gene_Namespace_Special {
	/**
	 * Calls page in this namespace.
	 *
	 * @static
	 * @var $id string Page ID in Namespace
	 * @var $action array Action Argument String
	 * @return bool Status
	 */
	function call($id, $action=array()) {
		$tpl =& Gene::getTemplate();
		$auth =& Gene::getAuth();
		$user =& Gene::getUser();
		
		if (isset($action[1])) {
			$method = $action[1];
		} else {
			$method = "main";
		}
		
		$id = strtolower($id);

		$modules = Gene::getSetting("special_pages");

		if (isset($modules[$id])) {
			// Check required permissions
			$view = false;
			foreach ($modules[$id] as $i) {
				if (in_array($i, $user->getPermissionMasks())) {
					$view = true;
				}
			}
			
			if (in_array("!gene-require-pwconfirm", $modules[$id]) && $auth->requirePasswordRetype()) {
				$returnurl = Gene::specialID($id);
				if (count($action)) {
					foreach ($action as $i) {
						$returnurl .= '/'.urlencode($i);
					}
				}
				$tpl->assign ("returnurl", $returnurl);
				Gene_Namespace_Special::call("Retype");
				return true;
			}
			
			if (!$view) {
				if (!$auth->loggedIn()) {
					header ("Location: ".Gene::makeLink(Gene::specialId("Login")));
					exit();
				} else {
					$tpl->assign ("finalbody", $tpl->fetch("errors/permissionerror"));
					return true;
				}
			}

			require_once ("Gene/Special/".ucfirst(str_replace ("_", "", $id)).".php");

			/* call a function which can create a class, etc. */
			$classname = "Gene_Special_".$id;

			if (is_callable(array($classname, $method))) {
				call_user_func(array($classname, $method));
			} else {
				call_user_func(array($classname, "main"));
			}
			
			$tpl->assign("curlbase", Gene::makeLink(Gene::specialID($id)));
			
			return true;
		} else {
			return false;
		}
	}
	
	/**
	 * Exports document as XML.
	 *
	 * @var $id string Page ID
	 *
	 * @return boolean Status
	 */
	function exportXml($id) {
		return false;
	}
	
	/**
	 * Runs web services.
	 *
	 * @var $method string Method to Call
	 * @return array/bool Result
	 */
	function runWebServices($method) {
		return false;
	}
	
	/**
	 * Returns whether search is supported by this namespace
	 *
	 * @return bool Searchable Status
	 */
	function isSearchable() {
		return false;
	}
	
	/**
	 * Perform a search in this namespace
	 *
	 * @var $query string Search Term
	 * @var $start integer Result Offset
	 * @var $limit integer Number of Results
	 * @return array Results
	 */
	function search($query, $start=0, $limit=30) {
		return array();
	}
	
	/* This namespace does not implement intelliAnswer */
	function intelliAnswer($phrase) { return false; }
}

?>